// 引入mysql模块
const mysql = require('mysql')
// 创建连接池对象
const pool = mysql.createPool({
	host: '127.0.0.1',
	port: '3306',
	user: 'root',
	password: '',
	database: 'zhsq',
	// 开启执行多个SQL命令
	multipleStatements: true
})
// 执行SQL命令
/*
var id = 7
pool.query('delete from zh_fee_record where fid=?', [id], function(err,result) {
	if(err) {
		throw err
	}
	console.log(result)
	// 判断是否删除成功
	// 如果受影响的行位为0说明删除失败,否则删除成功
	if(result.affectedRows === 0) {
		console.log('删除失败')
	} else {
		console.log('删除成功')
	}
})
*/

// 假设每页显示5条数据
// 当用户传递页码后，查询出这一页的数据
var pno = 2
// select * from zh_fee_record limit 开始查询的值, 每页数据量;
// select count(*) from zh_fee_record
// 计算出开始查询的值
var start = (pno - 1) * 5
pool.query('select * from zh_fee_record limit ?,5; select count(*) as n from zh_fee_record',[start],function(err,result) {
	if(err) {
		throw err
	}
	// console.log(result)
	// 分别获取每一条SQL命令的结果
	console.log(result[0])
	console.log('--------------------------')
	console.log(result[1])
})
